package ACWing.Dynamicprogramming;
//902. 最短编辑距离
import java.util.Scanner;

/**
 * @author :chenjie
 * @date :Created 2022/11/13 19:34
 */
public class MinimumEditingDistance {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        String a1=sc.next();
        int m=sc.nextInt();
        String b1=sc.next();
        char[] a = a1.toCharArray();
        char[] b = b1.toCharArray();
        int[][]dp=new int[n+1][m+1];

        //初始化为0时的状态因为dp是用前面的状态计算所以这一个状态的值也要算进来
        for (int i = 0; i <= m; i++) {
            dp[0][i]=i;

        }
        for (int i = 0; i <= n; i++) {
            dp[i][0]=i;
        }

        for (int i = 1; i < n+1; i++) {
            for (int j = 1; j < m+1; j++) {
                dp[i][j]=Math.min(dp[i][j-1]+1,dp[i-1][j]+1);
                if(a[i-1]!=b[j-1]){
                    dp[i][j]=Math.min(dp[i][j],dp[i-1][j-1]+1);
                }else {
                    dp[i][j]=dp[i-1][j-1];
                }
            }
        }
        System.out.println(dp[n][m]);
    }
}
